<template>
  <BasicModal
    v-bind="$attrs"
    :title="isUpdate ? t('common.edit') : t('common.create')"
    @register="register"
    @ok="handleSubmit"
    :destroyOnClose="true"
    :minHeight="400"
    :width="700"
    ><BasicForm @register="registerForm"
  /></BasicModal>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicForm, useForm } from '/@/components/Form';
  import { useI18n } from '/@/hooks/web/useI18n';

  import { getAddForm } from './tableData';

  const { t } = useI18n();
  const isUpdate = ref<boolean>(false);

  // 提交
  async function handleSubmit() {
    const values = await validate();
    closeModal();
  }

  // 定义弹窗是否可见
  const [register, { closeModal }] = useModalInner((data) => {
    isUpdate.value = !!data?.isUpdate;
  });

  // 表单初始化
  const [registerForm, { validate }] = useForm({
    schemas: getAddForm(),
    labelWidth: 110,
    colon: true,
    labelCol: { span: 6 },
    wrapperCol: { span: 14 },
    showActionButtonGroup: false,
  });
</script>
